from bs4 import BeautifulSoup
from selenium import webdriver
import time
import re
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium_web_ctrl import scroll_screen
from content_extract import extract

def login_twitter(browser):
    browser.get(r'https://twitter.com/login')
    username = '+8615313785562'
    time.sleep(10)
    password = '1qaz@WSX'
    name_imput= browser.find_element_by_xpath('//input[@name="session[username_or_email]"]')

    password_imput = browser.find_element_by_xpath('//input[@name="session[password]"]')
    name_imput.send_keys(username)
    time.sleep(3)
    password_imput.send_keys(password)
    time.sleep(3)
    browser.find_element_by_xpath('//div[@data-testid="LoginForm_Login_Button"]').click()



if __name__ == '__main__':
    print("start...")
    chrome_options = Options()
    #chrome_options.add_argument("--headless")
    chrome_options.add_argument('--ignore-certificate-errors')
    path = r'E:\Code\Python\tools\chromedriver.exe'
    browser = webdriver.Chrome(executable_path=path, chrome_options=chrome_options)
    login_twitter(browser)
    # browser.get(r'https://twitter.com/i/trends')
    # browser.get(r'https://twitter.com/search?q=sanktionen China since:2021-03-22 until:2021-03-24&src=typed_query')
    browser.get(r'https://twitter.com/search?q=(china OR chinese) since:2020-04-02 until:2020-04-03&src=typed_query&f=live')
                #'https://twitter.com/search?q=(china OR chinese) since:2020-04-02 until:2020-04-03&src=typed_query&f=live'

    scroll_screen(browser, extract)
    # browser.get(
    #      r'https://twitter.com/search?q=sanktionen China since:2021-03-22 until:2021-03-24&src=typed_query&f=live')
    # browser.get(
    #     r'https://twitter.com/search?q=China since:2021-03-01 until:2021-03-24&src=typed_query&f=live')
    # scroll_screen(browser, extract)
    # browser.quit()
    print("end crawl..")
